package grape.attend.service.vacation.api;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import grape.attend.service.vacation.po.Vacation;
import grape.common.service.common.IBaseService;
import grape.common.service.trans.ITransService;

/**
 * <p>
 * 假期表 服务类
 * </p>
 *
 * @author yangwei
 * @since 2020-05-08
 */
public interface IVacationService extends IBaseService<Vacation>, ITransService<String,String> {
    public static final String trans_vacationName = "vacationName";
    /**
     * 判断编码是否已存在
     * @param code
     * @return
     */
    default boolean existCode(String code){
        assertParamNotEmpty(code,"code 不能为空");

        Vacation vacation = new Vacation();
        vacation.setCode(code);
        int r = count(Wrappers.query(vacation));
        return r > 0;
    }
    /**
     * 根据编码查询
     * @param code
     * @return
     */
    default Vacation getByCode(String code) {
        assertParamNotEmpty(code,"code不能为空");
        Vacation vacation = new Vacation();
        vacation.setCode(code);
        return getOne(vacation);

    }
    @Override
    default boolean support(String type){
        return isEqualAny(type,trans_vacationName);
    }

    @Override
    default String trans(String type, String key){
        if (isEqual(type,trans_vacationName)) {
            Vacation po = getById(key);
            return po.getName();
        }
        return null;
    }
}
